package com.example.seh.person;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.seh.R;

import java.util.List;

public class AddressAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> addressList;
    private int item;

    public AddressAdapter(Context mContext, List<String> addressList, int item) {
        this.mContext = mContext;
        this.addressList = addressList;
        this.item = item;
    }

    @Override
    public int getCount() {
        if (addressList != null) {
            return addressList.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (addressList != null) {
            return addressList.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(item, null);
            viewHolder = new ViewHolder();
            viewHolder.address = convertView.findViewById(R.id.address_item);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.address.setText(addressList.get(position));
        return convertView;
    }
    class ViewHolder{
        private TextView address;
    }
}
